<template>
  <div class="Notification-container">
    <slot></slot>
    <div class="item" v-for="(item,index) in list" :key="index" :class="{isread:item.isread}" @click="handleRead(item,index)">
      <img :src="item.url" alt srcset />
      <div class="content">
        <span class="title">{{item.title | fliterTitle}}</span>
        <br />
        <span class="time">{{item.time}}</span>
      </div>
    </div>
  </div>
</template>


<script>
export default {
  data() {
    return {
      list:[]
    };
  },
  filters:{
    fliterTitle(v){
      return v.substring(0,30) + '...'
    }
  },
  methods:{
    handleRead(item,index){
      this.list.forEach((el,idx)=>{
        idx==index?(el.isread=true,this.$emit('handleRead')):el.isread=el.isread
      })
    }
  }
};
</script>


<style lang="scss" scoped>
.Notification-container {
  .top-header{
    height: 30px;
    text-align: center;
    line-height: 30px;
    cursor: pointer;
    border: 1px solid #409EFF;
    margin: 0 10px;
    border-radius: 5px;
    color: #409EFF;
  }
  .item {
    display: flex;
    flex-direction: row;
    height: 60px;
    padding-top: 10px;
    border-bottom: 1px solid #e9e7e7;
    cursor: pointer;
    img {
      width: 40px;
      height: 40px;
      margin-left: 15px;
    }
    .content {
      margin-left: 15px;
      .title {
        font-size: 16px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .time {
        font-size: 12px;
        color: #999;
      }
    }
  }
  .isread {
    opacity: 0.5;
  }
}
</style>
